package com.jason.canvas.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

/**
 * @DESC: Path addxxx方法直接往Path中添加一些曲线
 * @Author: Jason
 * @Date: 16/9/19
 * @Time: 15:14
 */

public class PathArc10 extends View {

    private Path mPath;
    private Paint mPaint;

    public PathArc10(Context context, AttributeSet attrs) {
        super(context, attrs);

        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setColor(Color.CYAN);
        mPaint.setStrokeWidth(5);

        mPath = new Path();
        mPath.moveTo(100, 100);
        mPath.lineTo(200, 200);

        // 添加一条弧线到Path中
        RectF oval = new RectF(100, 100, 300, 400);
        mPath.addArc(oval, 0, 90);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        // 绘制路径
        canvas.drawPath(mPath, mPaint);
    }

    /**
     *  addCircle(float x, float y, float radius, Path.Direction dir)
     *  addOval(float left, float top, float right, float bottom, Path.Direction dir)
     *  addRect(float left, float top, float right, float bottom, Path.Direction dir)
     *  addRoundRect(float left, float top, float right, float bottom, float rx, float ry, Path.Direction dir)
     *
     *  这些方法和addArc有很明显的区别，就是多了一个Path.Direction参数
     *  addArc是往Path中添加一段弧，说白了就是一条开放的曲线，而上述几种方法都是一个具体的图形，或者说是一条闭合的曲线
     *  Path.Direction的意思就是标识这些闭合曲线的闭合方向
     */
}
